import React, { Component } from 'react';
// import service from '../../api'
// import { IndexBar, List } from 'antd-mobile'
import context from '../../utils/context';
import { withRouter } from 'react-router-dom'
import './Header.scss'
class Header extends Component<any, any> {
    constructor(props: any) {
        super(props)
        this.state = {
            city: {
                name: '北京',
                isHot: 1
            },
            isLogin: false
        }
    }
    componentDidMount(): void {
        var token = localStorage.getItem('token')
        if (token) {
            this.setState({
                isLogin: true
            })
        }
        var city = localStorage.getItem('city')
        //  city=JSON.parse(city)
        if (city) {
            city = JSON.parse(city)
            this.setState({
                city
            })
        }
    }
    toCity() {
        console.log(this.props)
        this.props.history.push('/city')
    }
    toSearch() {
        this.props.history.push('/search')
    }
    toLogin() {
        this.props.history.push('/login')
    }
    render() {
        // console.log(this.context);
        return (
            <div className='header'>
                <span onClick={() => { this.toCity() }} className={this.state.city.isHot === 1 ? 'hot' : ''}>
                    {this.state.city.name}
                </span>
                <div className='search' onClick={this.toSearch.bind(this)}>

                </div>
                {
                    this.state.isLogin ? <span>欢迎</span> : <span onClick={this.toLogin.bind(this)}>
                        登录
                    </span>
                }

            </div>
        );
    }
}
Header.contextType = context
export default withRouter(Header);